<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action = $_REQUEST['act'];
	
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("SELECT			DISTINCT
													transfer_detail.id													AS id,
													DATE(transfer.date) 												AS date,
													production.name 													AS name,
													SUM(transfer_detail.quantity ) 										AS quantity,
													ROUND(reserve.real_price, 2)										AS price,
													ROUND((reserve.real_price * SUM(transfer_detail.quantity)), 2)		AS sum,
													ROUND(pricelist.price, 2),
													ROUND((SUM(transfer_detail.quantity ) * pricelist.price), 2)
									FROM 			transfer 															LEFT JOIN  transfer_detail
									ON				transfer.id = transfer_detail.transfer_id 							LEFT JOIN production
									ON				transfer_detail.production_id = production.id						LEFT JOIN reserve
									ON				reserve.production_id = transfer_detail.production_id && DATE(transfer.date) = DATE(reserve.create_date) LEFT JOIN pricelist
									ON				production.id	= pricelist.production_id
									WHERE 			transfer.target_id = 8 && reserve.object_id = 8 
									GROUP BY		reserve.production_id, reserve.create_date           
									");
			
			$output = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$output['aaData'][] = $row;
			}
			
			echo json_encode( $output );

	        break;	    
	    default:
	       	echo "null";
	}
?>